<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>清理缓存</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
	<link href="../../../css/mui.css" rel="stylesheet"/>
	<link href="../../../css/mui.min.css" rel="stylesheet"/>
	<link href="../../../css/app.css" rel="stylesheet"/>
</head>
<body>
	<!-- 头部TITLE -->
	<header class="mui-bar mui-bar-nav mui-bar-transparent">
		<span class="mui-icon mui-icon-back" 
			onclick="jumpToMyset()"></span>
		<h1 class="mui-title app-header">清理缓存</h1>
	</header>
	<!-- 头部TITLE -->
	
	<!-- 主体部分 -->
	<div style="height: 45px;"></div>
	<ul class="mui-table-view">
		<li class="mui-table-view-cell" onclick="clearParam()">
			<a class="mui-navigate-right">
				系统参数
				<span class="app-small" id="sys"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" onclick="clearVersion()">
			<a class="mui-navigate-right">
				版本信息
				<span class="app-small" id="version"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" onclick="clearIndex()">
			<a class="mui-navigate-right">
				首页视频数据
				<span class="app-small" id="indexList"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" onclick="clearMarket()">
			<a class="mui-navigate-right">
				库视频数据
				<span class="app-small" id="marketList"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" onclick="clearOpinion()">
			<a class="mui-navigate-right">
				建议数据
				<span class="app-small" id="opinionList"></span>
			</a>
		</li>
		<li class="mui-table-view-cell">
			<a class="mui-navigate-right">
				文件数据
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="clearRewSign()">
			<a class="mui-navigate-right">
				签签乐数据
				<span class="app-small" id="rewSignList"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="clearRewShake()">
			<a class="mui-navigate-right">
				摇一摇数据
				<span class="app-small" id="rewShakeList"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="clearRewScan()">
			<a class="mui-navigate-right">
				开心扫数据
				<span class="app-small" id="rewScanList"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="clearRewDraw()">
			<a class="mui-navigate-right">
				免费刮数据
				<span class="app-small" id="rewDrawList"></span>
			</a>
		</li>
	</ul>
	<!-- 主体部分 -->
	
	<!-- 底部菜单 -->
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item" onclick="jumpToIndex()">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">库</span>
		</a>
		<a class="mui-tab-item" onclick="jumpToReward()">
			<span class="mui-icon mui-icon-spinner-cycle"></span>
			<span class="mui-tab-label">奖励</span>
		</a>
		<a class="mui-tab-item mui-active" onclick="jumpToMy()">
			<span class="mui-icon mui-icon-contact"></span>
			<span class="mui-tab-label">我的</span>
		</a>
	</nav>
	<div style="height: 45px;"></div>
	<!-- 底部菜单 -->
</body>
</html>

<script src="../../../js/mui.js"></script>
<script src="../../../js/mui.min.js"></script>
<script src="../../../js/app.js"></script>
<script src="../../../js/views/view.js"></script>
<script type="text/javascript">
	// mui.init()
	//自动加载
	(function($, owner) {
		getParam();
		getVersion();
		getIndexList();
		getMarketList();
		getOpinionList();
		getRewSignList();
		getRewShakeList();
		getRewScanList();
		getRewDrawList();
	}(mui, window.app = {}));
	// 获取系统参数缓存
	function getParam(){
		var cache = cacheGet(sysKey);
		if (cache) {
			mui("#sys")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#sys")[0].innerHTML = '无缓存';
		}
	}
	// 清理系统参数缓存
	function clearParam(){
		clearKey(sysKey);
	}
	// 获取版本信息
	function getVersion(){
		var ver = cacheGet(appVersionKey);
		var h ='';
		if (ver==null) {
			mui("#version")[0].innerHTML = '无信息';
		} else {
			h = '当前版本：'+ver.version+'，链接：'+ver.link;
			mui("#version")[0].innerHTML = h;
		}
	}
	// 清理版本数据缓存
	function clearVersion(){
		clearKey(appVersionKey);
	}
	// 获取首页历史数据缓存
	function getIndexList(){
		var cache = cacheGet(indexList);
		if (cache) {
			mui("#indexList")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#indexList")[0].innerHTML = '无缓存';
		}
	}
	// 清理首页历史数据缓存
	function clearIndex(){
		clearKey(indexList);
	}
	// 获取库缓存
	function getMarketList(){
		var cache = cacheGet(marketList);
		if (cache) {
			mui("#marketList")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#marketList")[0].innerHTML = '无缓存';
		}
	}
	// 清理库数据缓存
	function clearMarket(){
		clearKey(marketList);
	}
	// 获取建议缓存
	function getOpinionList(){
		var cache = cacheGet(opinionList);
		if (cache) {
			mui("#opinionList")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#opinionList")[0].innerHTML = '无缓存';
		}
	}
	// 清理建议数据缓存
	function clearOpinion(){
		clearKey(opinionList);
	}
	// 获取签到缓存
	function getRewSignList(){
		var cache = cacheGet(rewardSignList);
		if (cache) {
			mui("#rewSignList")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#rewSignList")[0].innerHTML = '无缓存';
		}
	}
	// 清理签到数据缓存
	function clearRewSign(){
		clearKey(rewardSignList);
	}
	// 获取摇一摇缓存
	function getRewShakeList(){
		var cache = cacheGet(rewardShakeList);
		if (cache) {
			mui("#rewShakeList")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#rewShakeList")[0].innerHTML = '无缓存';
		}
	}
	// 清理摇一摇数据缓存
	function clearRewShake(){
		clearKey(rewardShakeList);
	}
	// 获取扫一扫缓存
	function getRewScanList(){
		var cache = cacheGet(rewardScanList);
		if (cache) {
			mui("#rewScanList")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#rewScanList")[0].innerHTML = '无缓存';
		}
	}
	// 清理扫一扫数据缓存
	function clearRewScan(){
		clearKey(rewardScanList);
	}
	// 获取刮奖缓存
	function getRewDrawList(){
		var cache = cacheGet(rewardDrawList);
		if (cache) {
			mui("#rewDrawList")[0].innerHTML = '有缓存-点击清除';
		} else {
			mui("#rewDrawList")[0].innerHTML = '无缓存';
		}
	}
	// 清理刮奖数据缓存
	function clearRewDraw(){
		clearKey(rewardDrawList);
	}
	// 清理缓存
	function clearKey(k){
		var cache = cacheGet(k);
		// mui.toast(cache.idstr); return
		if (!cache) {
			mui.toast('没有缓存',{ 
				duration:'long', type:'div',
			});
			return
		}
		// 更新请求
		setApiDel(k);
	}
	//请求接口，移除数据
	function setApiDel(k){
		var resList = '', resUrl = '';
		if (k==indexList) {
			resList = cacheGet(indexList);
			resUrl = '/app/video/history/del';
		} else if (k==marketList) {
			resList = cacheGet(marketList);
			resUrl = '/app/stock/history/del';
		} else {
			cacheDel(k);
			mui.toast('清理成功',{ 
				duration:'long', type:'div',
			});
			// 不需要请求的
			setTimeout(function(){
				jumpToMysetCache();
			}, 1000);
			return
		}
		var idstr = resList.idstr;
		// 系统参数
		var sys = getSys();
		if (sys==null || sys.appAccess=='') { 
			setSys(); //参数更新
			setTimeout(function(){
				jumpToMarket();
			}, 1000);
		} 
		// 用户信息
		var userInfo = cacheGet(userInfoKey);
		var uid = userInfo ? userInfo.uid : 0;
		if (uid==0) {
			mui.toast('没有登陆',{ 
				duration:'short', type:'div',
			});
			setTimeout(function(){
				jumpToMyLogin();
			}, 500);
			return
		}
		mui.ajax(sys.domain+resUrl,{
			data:{
				appAccess: sys.appAccess,
				uid:uid,
				idstr:idstr
			},
			dataType:'json', //服务器返回json格式数据
			type:'post', //HTTP请求类型
			timeout:10000, //超时时间设置为10秒
			headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
			success:function(res){
				// console.log(res)
				if (res.code==-1) {
					mui.toast('需要更新系统参数',{ 
						duration:'long', type:'div',
					});
					setTimeout(function(){
						setSys();
						jumpToMysetCache();
					},500);
				} else if (res.code!=0) { 
					// mui.toast('ERR'+res.code);
					mui.toast('清理失败');
					return
				}
				cacheDel(k);
				mui.toast('清理成功',{ 
					duration:'long', type:'div',
				});
				setTimeout(function(){
					jumpToMysetCache();
				}, 1000);
			},
			error:function(xhr,type,errorThrown){
				mui.toast('网络错误！',{ 
					duration:'short', type:'div',
				});
			}
		});
	}
</script>